package com.ygy.config;

import com.ygy.intercptors.LoginIntercptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    // 解决Vue前端axios跨域问题 (简写形式)
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("http://localhost:8080")
 //               .allowCredentials(true)
               // .allowedOriginPatterns("*")
                .allowedHeaders("*")
                .allowCredentials(true) // 允许携带cookie
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                .maxAge(3600);
    }

        /**
         * @className: WebConfig
         * @author: Ye
         * @描述:拦截器配置到mvc
         * @date: 2024/3/11 13:46
         * @version: 1.0
         */
    @Autowired
    private LoginIntercptor loginIntercptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //登录接口和注册接口不拦截
        registry.addInterceptor(loginIntercptor).excludePathPatterns(
                "/comments/addComment","/comments/commentList/{productId}/{userId}","/like/like","/ord/delete","/ord/**","/alipay/**",
                "/users/**","/users/loginUser" ,"/uploads","/views","/pro/page","/fav/add","/fav/cf","/fav/delete","/pro/update" ,"/evaluations/**","/pro/**");
    }
       /* registry.addInterceptor(loginIntercptor).excludePathPatterns(
                "/users/page","/users/delete","/users/register","/users/loginUser","/users/list","/users/update",
                 "/uploads","/views" ,"/pro/delete","/pro/page","/pro/update","/users/userId","/pro/wofabu" );
    }*/
}
